<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:s="http://jboss.org/seam/faces"
      xml:lang="en" lang="en">

<ui:composition template="/resources/layout.xhtml">
    <ui:define name="title" >Реестр займов</ui:define>
    <ui:define name="content">
        <div class="all_loan_list_page">
            <h:form id="addNewLoanForm">

            <rich:dataTable id="loanList" value="#{loanAction.allLoansForCurrentFilial}" var="loan" >

                <rich:column sortBy="#{loan.debtor.FIO}"
                             sortOrder="#{loanAction.loanListSort.debtorOrder}"
                             styleClass="#{(loan.isFinished ? 'finish-loan' : (loan.loanOverdue ? 'overdue' : ''))}"
                        >
                    <f:facet name="header">
                        <a4j:commandLink value="Заниматель"
                                         render="loanList"
                                         styleClass="fake-app"
                                         title="Заниматель"
                                         action="#{loanAction.loanListSort.sortByDebtor}" />
                    </f:facet>
                    <h:outputText value="#{loan.debtor.FIO}" />
                </rich:column>

                <rich:column sortBy="#{loan.amount}"

                             sortOrder="#{loanAction.loanListSort.amountOrder}"
                             styleClass="#{(loan.isFinished ? 'finish-loan' : (loan.loanOverdue ? 'overdue' : ''))} number-column">
                    <f:facet name="header">
                        <a4j:commandLink value="Сумма займа"
                                         styleClass="fake-app"
                                         render="loanList"
                                         title="Сумма займа"
                                         action="#{loanAction.loanListSort.sortByAmount}" />
                    </f:facet>
                    <h:outputText value="#{loan.amount}" >
                        <f:convertNumber pattern="###,##0.0" />
                    </h:outputText>
                </rich:column>

                <rich:column sortBy="#{loan.createDate}"
                             sortOrder="#{loanAction.loanListSort.createDateOrder}"
                             styleClass="#{(loan.isFinished ? 'finish-loan' : (loan.loanOverdue ? 'overdue' : ''))} date-column">
                    <f:facet name="header">
                        <a4j:commandLink value="Дата договора"
                                         render="loanList"
                                         styleClass="fake-app"
                                         title="Дата заключения договора"
                                         action="#{loanAction.loanListSort.sortByCreateDate}" />
                    </f:facet>
                    <h:outputText value="#{loan.createDateStr}" />
                </rich:column>

                <rich:column sortBy="#{loan.period}"
                             sortOrder="#{loanAction.loanListSort.periodOrder}"
                             styleClass="#{(loan.isFinished ? 'finish-loan' : (loan.loanOverdue ? 'overdue' : ''))} number-column">
                    <f:facet name="header">
                        <a4j:commandLink value="Срок займа"
                                         render="loanList"
                                         styleClass="fake-app"
                                         title="Срок займа"
                                         action="#{loanAction.loanListSort.sortByPeriod}" />
                    </f:facet>
                    <h:outputText value="#{loan.period}" styleClass="number" />
                </rich:column>

                <rich:column sortBy="#{loan.plannedAmount}"
                             sortOrder="#{loanAction.loanListSort.plannedAmountOrder}"
                             styleClass="#{(loan.isFinished ? 'finish-loan' : (loan.loanOverdue ? 'overdue' : ''))} number-column">
                    <f:facet name="header">
                        <a4j:commandLink value="Сумма долга"
                                         styleClass="fake-app"
                                         render="loanList"
                                         title="Расчитанная планируемая сумма долга"
                                         action="#{loanAction.loanListSort.sortByPlannedAmount}" />
                    </f:facet>
                    <h:outputText value="#{loan.plannedAmount}">
                        <f:convertNumber pattern="###,##0.0" />
                    </h:outputText>
                </rich:column>

                <rich:column sortBy="#{loan.feeForUseOfFunds}"
                             sortOrder="#{loanAction.loanListSort.feeForUseOfFundsOrder}"
                             styleClass="#{(loan.isFinished ? 'finish-loan' : (loan.loanOverdue ? 'overdue' : ''))} number-column">
                    <f:facet name="header">
                        <a4j:commandLink value="Плата за п.д.с."
                                         styleClass="fake-app"
                                         render="loanList"
                                         action="#{loanAction.loanListSort.sortByFeeForUseOfFunds}"
                                         title="Плата за пользование денежными средствами"/>
                    </f:facet>
                    <h:outputText value="#{loan.feeForUseOfFunds}">
                        <f:convertNumber pattern="###,##0.0" />
                    </h:outputText>
                </rich:column>

                <rich:column sortBy="#{loan.plannedDate}"
                             sortOrder="#{loanAction.loanListSort.plannedDateOrder}"
                             styleClass="#{(loan.isFinished ? 'finish-loan' : (loan.loanOverdue ? 'overdue' : ''))} date-column">
                    <f:facet name="header">
                        <a4j:commandLink value="Дата исполнения обязательств"
                                         render="loanList"
                                         styleClass="fake-app"
                                         title="Дата исполнения обязательств"
                                         action="#{loanAction.loanListSort.sortByPlannedDate}" />
                    </f:facet>
                    <h:outputText value="#{loan.plannedDateStr}" />
                </rich:column>

                <rich:column sortBy="#{loan.overdueDays}"
                             sortOrder="#{loanAction.loanListSort.overdueDaysOrder}"
                             styleClass="#{(loan.isFinished ? 'finish-loan' : (loan.loanOverdue ? 'overdue' : ''))} number-column">
                    <f:facet name="header">
                        <a4j:commandLink value="Кол-во просроченных дней"
                                         render="loanList"
                                         styleClass="fake-app"
                                         title="Количество просроченных дней"
                                         action="#{loanAction.loanListSort.sortByOverdueDays}" />
                    </f:facet>
                    <h:outputText value="#{loan.overdueDays}" rendered="#{loan.loanOverdue}"/>
                </rich:column>

                <rich:column sortBy="#{loan.currentAmount}"
                             sortOrder="#{loanAction.loanListSort.currentAmountOrder}"
                             styleClass="#{(loan.isFinished ? 'finish-loan' : (loan.loanOverdue ? 'overdue' : ''))} number-column">
                    <f:facet name="header">
                        <a4j:commandLink value="Текущая сумма долга"
                                         render="loanList"
                                         styleClass="fake-app"
                                         title="Текущая сумма долга с учётом штрафов"
                                         action="#{loanAction.loanListSort.sortByCurrentAmount}" />
                    </f:facet>
                    <h:outputText value="#{loan.currentAmount}">
                        <f:convertNumber pattern="###,##0.0" />
                    </h:outputText>
                </rich:column>

                <rich:column sortBy="#{loan.factFeeForUseOfFunds}"
                             sortOrder="#{loanAction.loanListSort.factFeeForUseOfFundsOrder}"
                             styleClass="#{(loan.isFinished ? 'finish-loan' : (loan.loanOverdue ? 'overdue' : ''))} number-column">
                    <f:facet name="header">
                        <a4j:commandLink value="Текущая плата за п.д.с."
                                         styleClass="fake-app"
                                         render="loanList"
                                         title="Текущая плата за пользование денежными средствами"
                                         action="#{loanAction.loanListSort.sortByFactFeeForUseOfFunds}" />
                    </f:facet>
                    <h:outputText value="#{loan.factFeeForUseOfFunds}">
                        <f:convertNumber pattern="###,##0.0" />
                    </h:outputText>
                </rich:column>

                <rich:column sortBy="#{loan.owner.filial.name}"
                             sortOrder="#{loanAction.loanListSort.filialOrder}"
                             styleClass="#{(loan.isFinished ? 'finish-loan' : (loan.loanOverdue ? 'overdue' : ''))}"
                             rendered="#{identity.hasRole('admin', 'default', 'default')}"
                        >
                    <f:facet name="header">
                        <a4j:commandLink value="Филиал"
                                         render="loanList"
                                         styleClass="fake-app"
                                         title="Филиал"
                                         action="#{loanAction.loanListSort.sortByFilial}" />
                    </f:facet>
                    <h:outputText value="#{loan.owner.filial.name}" />
                </rich:column>
            </rich:dataTable>
            </h:form>
        </div>
    </ui:define>
</ui:composition>

</html>
